package com.集合.Collection___.List_;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
@SuppressWarnings("all")

public class ListExercise02  {
    public static void main(String[] args) {

        List list = new ArrayList();
        list.add(new Book("红楼梦","曹雪芹",100.9));
        list.add(new Book("西游记","吴承恩",90));
        list.add(new Book("水浒传","施耐庵",60.6));
        list.add(new Book("三国杀","罗贯中",709));
        list.add(new Book("Java" ,"韩顺平",88.8));
          list = fun(list);


        for (Object o : list) {
            System.out.println(o);
        }


        }
    static List fun(List list) {
        Object obj;

        for (int i = 0; i < list.size() -1; i++) {
            for (int j = 0; j < list.size() - 1 - i; j++) {
                Book b1 = (Book)list.get(j);
                Book b2 = (Book)list.get(j+1);

                if(b1.getPrice() > b2.getPrice() ){
                    list.set(j, b2);
                    list.set(j+1, b1);
                }
            }

        }
        return list;
    }

}

class Book{
    private String name;
    private String author;
    private  double price;

    public Book(String name, String author, double price) {
        this.name = name;
        this.author = author;
        this.price = price;
    }

    @Override
    public String toString() {
        return "名称：'" + name + "\t\t\t" + "价格：'" + price + "\t\t\t"+ " price=" + author;
    }

    public String getName() {
        return name;
    }

    public String getAuthor() {
        return author;
    }

    public double getPrice() {
        return price;
    }
}
